<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <title>菜单管理--右边列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="/favicon.ico">
    <link rel="stylesheet" href="/resources/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/resources/css/public.css" media="all" />
    <link rel="stylesheet" href="/resources/layui_ext/dtree/dtree.css" media="all" />
    <link rel="stylesheet" href="/resources/layui_ext/dtree/font/dtreefont.css" media="all" />

</head>
<body class="childrenBody">


            <!-- 查询条件开始 -->
            <form action="" method="post" id="searchFrm" lay-filter="searchFrm" class="layui-form layui-form-pane">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">患者姓名</label>
                        <div class="layui-input-inline">
                            <select name="patientid" id="patientid_search"   lay-filter="patientid_search" lay-search="">
                                <option value="0">请选择患者姓名</option>
                            </select>
                        </div>

                        <label class="layui-form-label">开始时间</label>
                        <div class="layui-input-inline">
                            <input type="tel" name="startTime" id="startTime" readonly="readonly" placeholder="yyyy-MM-dd HH:mm:ss" class="layui-input">
                        </div>

                        <label class="layui-form-label">结束时间</label>
                        <div class="layui-input-inline">
                            <input type="tel" name="endTime"  id="endTime"  readonly="readonly" placeholder="yyyy-MM-dd HH:mm:ss" class="layui-input">
                        </div>

                        <div class="layui-input-inline">
                            <button type="button" class="layui-btn" lay-submit="" lay-filter="doSearch"><span class="layui-icon layui-icon-search"></span>查询</button>
                            <button type="reset" class="layui-btn layui-btn-warm"><span class="layui-icon layui-icon-refresh-1"></span>重置</button>
                        </div>
                    </div>
                </div>
            </form>
            <!-- 查询条件结束-->
            <!-- 数据表格开始 -->
            <div>
                <table class="layui-hide" id="guahaoTable" lay-filter="guahaoTable"></table>
                <div id="guahaoToolBar" style="display: none;">
                    <button type="button" lay-event="add" class="layui-btn layui-btn-sm"><span class="layui-icon layui-icon-add-1"></span>增加挂号</button>
                </div>
                <div id="guahaoRowBar" style="display: none;">
                    <button type="button" lay-event="update" class="layui-btn layui-btn-sm"><span class="layui-icon layui-icon-edit"></span>更新</button>
                    <button type="button" lay-event="delete" class="layui-btn layui-btn-sm layui-btn-danger"><span class="layui-icon layui-icon-delete"></span>删除</button>
                </div>
            </div> <!-- 数据表格结束 -->


<!-- 添加和修改的弹出层开始 -->
<div style="display:none;padding: 5px" id="addOrUpdateDiv">
    <form action="" method="post" class="layui-form layui-form-pane" id="dataFrm" lay-filter="dataFrm">
        <!-- //左侧患者信息-->
        <div class="layui-row">
            <div class="layui-col-xs6" >
                <div class="layui-form-item">
                    <label class="layui-form-label">患者姓名</label>
                    <div class="layui-input-block" style="width: 40%;">
                        <input type="hidden" name="id">
                        <select name="patientid"  id="patientid"  lay-filter="patientid" lay-search="">
                            <option value="0">请选择患者姓名</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">身份证号码</label>
                    <div class="layui-input-block">
                        <input type="text" name="idcardnum" id="idcardnum"  lay-verify="required" placeholder="请输入标题"
                               autocomplete="off" class="layui-input" style="width: 50%;">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">性别</label>
                    <div class="layui-input-block">
                        <input type="radio" name="sex" value="1" title="男" checked="">
                        <input type="radio" name="sex" value="0" title="女" >
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">年龄</label>
                    <div class="layui-input-block">
                        <input type="text" name="age" id="age" lay-verify="required" placeholder="请输入标题"
                               autocomplete="off" class="layui-input" style="width: 50%;">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">联系方式</label>
                    <div class="layui-input-block">
                        <input type="text" name="phone" id="phone"  lay-verify="required" placeholder="请输入标题"
                               autocomplete="off" class="layui-input" style="width: 50%;">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">就诊方式</label>
                    <div class="layui-input-block">
                        <input type="radio" name="status" value="1" title="初诊" checked="">
                        <input type="radio" name="status" value="0" title="复诊" >
                    </div>
                </div>
            </div>
            <!--右侧医生和订单信息-->
            <div class="layui-col-xs6">
                <div class="layui-form-item" >
                    <label class="layui-form-label">科室</label>
                    <div class="layui-input-block" style="width: 40%;">
                        <select name="deptid" id="deptid"   lay-filter="deptid" lay-search="">
                            <option value="0">请选择科室</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">医生</label>
                    <div class="layui-input-block" style="width: 40%;">
                        <select name="userid" id="userid"   lay-filter="userid" lay-search="">
                            <option value="0">请选择医生</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">门诊类型</label>
                    <div class="layui-input-block" style="width: 40%;">
                      <!--  <input type="text" name="type"   lay-verify="required" placeholder="下拉树"
                               autocomplete="off" class="layui-input" style="width: 50%;">-->
                        <select name="type" id="type" lay-verify="" lay-filter="type" autocomplete="off"  placeholder="下拉树" >
                            <option value="0">请选择</option>
                            <option value="专家">专家</option>
                            <option value="普通">普通</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">应收费用/元</label>
                    <div class="layui-input-block">
                        <input type="text" name="guahaoprice" id="guahaoprice"  placeholder="请输入标题"
                               autocomplete="off" disabled class="layui-input" style="width: 50%;">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">实收费用/元</label>
                    <div class="layui-input-block">
                        <input type="text" name="guahaotrueprice"  id="guahaotrueprice" lay-verify="required" placeholder="请输入标题"
                               autocomplete="off" class="layui-input" style="width: 50%;">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">支付方式</label>
                    <div class="layui-input-block">
                        <input type="radio" name="paytype" value="支付宝" title="支付宝" >
                        <input type="radio" name="paytype" value="微信" title="微信" >
                        <input type="radio" name="paytype" value="信用卡" title="信用卡" >
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block" style="padding-left: 300px;">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="doSubmit" ><span class="layui-icon layui-icon-add-1"></span>保存</button>
                <button type="reset" class="layui-btn layui-btn-warm"><span class="layui-icon layui-icon-refresh-1"></span>重置</button>
            </div>
        </div>
    </form>
</div>
<!-- 添加和修改的弹出层结束 -->


<script type="text/javascript" src="/resources/layui/layui.js"></script>
<script type="text/javascript">
    var tableIns;
    layui.extend({
        dtree: '/resources/layui_ext/dtree/dtree'   // {/}的意思即代表采用自有路径，即不跟随 base 路径
    }).use(['jquery','form','table','layer','laydate'],function(){
        var $=layui.jquery;
        var form=layui.form;
        var table=layui.table;
        var layer=layui.layer;
        var laydate=layui.laydate;
        //渲染时间选择器
        laydate.render({
            elem:'#startTime',
            type:'datetime'
        });
        laydate.render({
            elem:'#endTime',
            type:'datetime'
        });
        //加载 数据
        tableIns=table.render({
            elem: '#guahaoTable'
            ,url:'/guahao/loadAllGuahao'
            ,toolbar: '#guahaoToolBar' //开启头部工具栏，并为其绑定左侧模板
            ,title: '挂号列表'
            ,height:'full-150'
            ,page: true
            ,cols: [ [
                {field:'id', title:'id',align:'center',width:'80',hide:true}
                ,{type:'numbers', title:'序号',align:'center',width:'80'}
                ,{field:'Status', title:'状态',align:'center',width:'100',templet:function (d) {
                        return d.open==1?'<font >初诊</font>':'<font >复诊</font>';
                    }}
                ,{field:'type', title:'门诊类型',align:'center',width:'150'}
                ,{field:'patient', title:'患者姓名',align:'center',width:'150',templet:function (res) {
                        return '<span>'+res.patient.patientname+'</span>';
                    }}
                ,{type:'numbers', title:'就诊序号',align:'center',width:'80'}
                ,{field:'sex', title:'性别',align:'center',width:'80',templet:function(d){
                        return d.open==1?'<font color=blue>男</font>':'<font color=red>女</font>';
                    }}
                ,{field:'menzhentitle', title:'科室(外表)',align:'center',width:'100'}
                ,{field:'createtime', title:'挂号时间',align:'center',width:'200'}
                ,{fixed: 'right', title:'操作', toolbar: '#guahaoRowBar',align:'center',width:'300'}
            ] ]
            ,done: function(res, curr, count){ //处理删除某一页最后一条数据的BUG
                if(res.data.length==0&&curr!=1){
                    tableIns.reload({
                        page:{
                            curr:(curr-1)
                        }
                    });
                }
            }
        });

        //加载查询条件患者的下拉列表
        $.get("/patient/loadAllPatient",function(res){
            var data=res.data;
            var dom=$("#patientid_search");
            var html='<option value="0">请选择供患者</option>'
            $.each(data,function(index,item){
                html+='<option value="'+item.id+'">'+item.patientname+'***'+item.idcardnum.substring(14,18)+'</option>'
            });
            dom.html(html);
            form.render("select");
        });

        //模糊查询
        form.on("submit(doSearch)",function(data){
            tableIns.reload({
                where:data.field,
                page:{
                    curr:1
                }
            });
            return false;
        });

        //监听工具头的事件
        table.on("toolbar(guahaoTable)",function(obj){
            switch(obj.event){
                case 'add':
                    openAddLayer();
                    break;
            };
        });
        //监听行工具条的事件
        table.on("tool(guahaoTable)",function(obj){
            var data = obj.data; //获得当前行数据
            switch(obj.event){
                case 'update':
                    openUpdateMenuLayer(data);
                    break;
                case 'delete':
                    deleteGuahao(data);
                    break;
            };
        });

        //初始化添加和修改页面的科室下拉树
        function initDetpSelect(Detpid){
            var dom=$("#detpid");
            dom.html("");
            $.get("/dept/loadDetpForSelectById",function(res){
                var data=res.data;
                var dom=$("#deptid");
                var html='<option value="0">请选择科室</option>'
                $.each(data,function(index,item){
                    html+='<option value="'+item.id+'">'+item.title+'</option>'
                });
                dom.html(html);
                //如果providerid有值就反选
                if(Detpid!=undefined){
                    dom.val(Detpid);
                }
                form.render("select");
            });
        }
        //监听添加页面的供应商下拉框的改变事件
        form.on('select(deptid)', function(data){
            var deptid=data.value;
            initDoctorSelect(deptid);
        });

        //加载科室下拉列表
        function initDoctorSelect(deptid,userid){
            $.get("/user/loadUsersByDeptId",{deptid:deptid},function(res){
                var data=res.data;
                var dom=$("#userid");
                var html='<option value="0">请选择医生</option>'
                $.each(data,function(index,item){
                    html+='<option value="'+item.id+'">'+item.name+'</option>'
                });
                dom.html(html);
                //如果goodsid有值就反选
                if(userid!=undefined){
                    dom.val(userid);
                }
                form.render("select");
            });
        }
        //加载患者名称下拉列表
        function initPatientSelect(patientid){
            $.get("/patient/loadAllPatient",function(res){
                var data=res.data;
                var dom=$("#patientid");
                var html='<option value="0">请选择供患者</option>'
                $.each(data,function(index,item){
                    html+='<option value="'+item.id+'">'+item.patientname+'***'+item.idcardnum.substring(14,18)+'</option>'
                });
                dom.html(html);
                //如果providerid有值就反选
                if(patientid!=undefined){
                    dom.val(patientid);
                }
                form.render("select");
            });
        }
        //监听添加按钮的患者名称的失去焦点事件
        form.on('select(type)', function(data){
            var type=data.value;
            //alert(type);
            if(type=='专家'){
                $("#guahaoprice").val(15);
                $("#guahaotrueprice").val(15);
            }else {
                $("#guahaoprice").val(10);
                $("#guahaotrueprice").val(10);
            }

        });

        //监听添加按钮的患者名称的失去焦点事件
        form.on('select(patientid)', function(data){
            var patientid=data.value;
           // alert(patientid);
            $.get("/patient/loadAllPatient",{id:patientid},function(res){
                var obj = res.data[0];
                //alert(obj.idcardnum);
                $("#idcardnum").val(obj.idcardnum);
                $("#phone").val(obj.phone);
                $("#sex").val(obj.sex);
                $("#age").val(obj.age);
            });
           // form.render();
        });


        var mainIndex;
        var url;
        //打开添加的弹出层
        function openAddLayer(){
            mainIndex=layer.open({
                type:1,
                content:$("#addOrUpdateDiv"),
                area:['1020px','450px'],
                title:'添加',
                success:function(){
                    $("#dataFrm")[0].reset();
                    url="/guahao/addGuahao";
                    initDetpSelect();//加载下拉树
                    initPatientSelect();
                   // initGoodsSelect(0,0);//加载下拉树
                   // $(".mydiv").hide();//做禁用的,不可修改
                    //在禁用的label下的div加上下面
                    // <div class="mydiv" title="不可修改" style="position:absolute;width:100%;height:100%;left:0px;top:0px;background:#fff;opacity:0;filter:alpha(opacity=0)"> </div>
                }
            });
        }


        form.on("submit(doSubmit)",function(data){
            alert(JSON.stringify(data.field));
            $.post(url,data.field,function(res){
                if(res.code==200){
                    tableIns.reload();
                }
                layer.msg(res.msg);
                layer.close(mainIndex);
            });
            $.post("/jiuzhen/addJiuzhen",data.field,function(res){
                if(res.code==200){
                    tableIns.reload();
                }
                layer.msg(res.msg);
                layer.close(mainIndex);
            });
            return false;
        });



        //删除
        function deleteGuahao(data){
            layer.confirm("",{},function (index) {
                $.post("/guahao/deleteGuahao", {id: data.id}, function (res) {
                    if (res.code === 200) {
                        tableIns.reload();
                    }
                    layer.msg(res.msg);
                });
                $.post("/jiuzhen/deleteJiuzhen", {id: data.field}, function (res) {
                    if (res.code == 200) {
                        tableIns.reload();
                    }
                    layer.msg(res.msg);
                });
                layer.close(index);
            });
        }

    });

    //给其它页面刷新当前页面数据表格的方法
    function reloadTable(id){
        tableIns.reload({
            where:{
                id:id
            },
            page:{
                curr:1
            }
        });
    }
</script>

</body>
</html>